 

import java.util.ArrayList;

/**
 * Container class for Trades
 * @author Stefan
 */
public class TradeContainer
{
    //Attributes

    private ArrayList<Trade> trades;
    private static TradeContainer instance = new TradeContainer();

    private TradeContainer()
    {
        trades = new ArrayList<Trade>();
    }

    /**
     * Singleton
     * @return Instance of TradeContainer
     */
    public static TradeContainer getInstance()
    {
        return instance;
    }

    public void addTrade(Trade trade)
    {
        trades.add(trade);
        
    }

    public int getSize()
    {
        return trades.size();
    }

    /**
     * Removes a trade from the TradeContainer
     * @param trade
     */
    public void deleteTrade(Trade trade)
    {
        trades.remove(trade);
    }

    public Trade findTradeID(String id)
    {
        Trade found = null;
        for(Trade trade : trades)
        {
            if (trade.getId().equals(id))
            {
                found = trade;
            }
        }
        return found;
    }

    /**
     * Find Order by id
     * @param id
     * @return Order
     */
    public Order findOrderID(String id)
    {
        Order found = null;
        for (Trade trade : trades)
        {
            if (trade instanceof Order)
            {
                if (trade.getId().equals(id))
                {
                    found = (Order)trade;
                }
            }
        }
        return found;
    }
    /**
     * Find Rent by id
     * @param id
     * @return Rent
     */
    public Rent findRentID(String id)
    {
        Rent found = null;
        for (Trade trade : trades)
        {
            if(trade instanceof Rent)
            {
                if (trade.getId().equals(id))
                {
                    found = (Rent)trade;
                }
            }
        }
        return found;
    }
}
